﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CBMS.Interfaces;
using CBMS.Models;
using System.Data.Objects.DataClasses;
using System.Data.Objects;
using System.Collections;
using CBMS.Objects;
using System.Data.Objects.SqlClient;
using CBMS.Common;
using System.Data.Common;
using System.Data.EntityClient;
using System.Data;
using System.Globalization;

namespace CBMS.Business
{
    public class SubCategoryRepository : BaseEntityRepository<SubCategory>, ISubCategoryRepository
    {
        public SubCategoryRepository()
            : base()
        {

        }
       public Boolean Insert(SubCategory objCate)
        {
            try
            {
                DbContext.AddToSubCategories(objCate);
                DbContext.SaveChanges();
                return true;             
            }
            catch
            {

            }
            return false;
        }
       public IList<ItemDTO> GetAllAbilityByCategory(string categoryId)
       {
           IList<ItemDTO> lstResult = new List<ItemDTO>();
           try
           {
               var query = (from cate in DbContext.SubCategories
                            where cate.category_id == categoryId
                            select new 
                            {
                                Id = cate.subcategory_id,
                                Name = cate.subcategory_name
                            }).ToList();
               int iRowsCount = query.Count;
               for (int i = 0; i < iRowsCount; i++)
               {
                   ItemDTO item = new ItemDTO(query[i].Id.ToString(), query[i].Name);
                   lstResult.Add(item);
               }
           }
           catch
           {
               return new List<ItemDTO>();
           }
           return lstResult;
       }
    }
}